<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Finance extends Seller_Controller
{
    private static $data = array();
    public function __construct()
    {
        parent::__construct();
        $this->load->model('Finance_model','finance_model');
        $this->checkUserFlag();
        $this->checkCompany();
    }
    //加载页面
    public function index()
    {
        $companyId = $this->checkCompany();
        $info = $this->finance_model->getList($companyId);
        if(empty($info['data'])) {
            $this->load->view('seller/finance/add.html');
        }else{
            $this->load->view('seller/finance/list.html');
        }
    }

    public function getList()
    {
        $companyId = $this->checkCompany();
        $info = $this->finance_model->getList($companyId);
        if($info){
            show200_admin($info['data'],1);
        }else{
            show400_admin();
        }
    }

    public function add()
    {
        $companyId = $this->checkCompany();
        $data=$this->input->post();
        if($data['password']!=$data['password_reapeat']){
            show300('两次密码输入不正确');
        }
        $info['phone']=$data['phone'];
        $info['trade_password']=md5($data['password']);
        $info['account']=$data['account'];
        $info['company_id']=$companyId;
        $info['user_name']=$data['user_name'];
        $info['status']=0;
        $info['type']=2;
        $info['create_time']=time();

        $res=$this->finance_model->add($info);
        if($res){
            show200('添加成功');
        }else{
            show400('添加失败');
        }
    }

    public function edit()
    {
        $this->load->view('seller/finance/edit.html');
    }
    public function update()
    {
        $data=$this->input->post();
        if($data['password']!=$data['password_reapeat']){
            show300('两次密码输入不正确');
        }
        $id = $data['id'];
        $info['phone']=$data['phone'];
        $info['trade_password']=md5($data['password']);
        $info['account']=$data['account'];
        $info['user_name']=$data['user_name'];
        $info['status']=1;
        $info['update_time']=time();

        $res=$this->finance_model->edit($id, $info);
        if($res){
            show200('修改成功，提交审核');
        }else{
            show400('修改失败');
        }
    }

    public function del()
    {
        $this->load->view('seller/finance/del.html');
    }

    public function deldata()
    {
        $data['id'] = $this->input->post('id', TRUE);
        $data['phone'] = $this->input->post('phone', TRUE);
        $data['trade_password'] = md5($this->input->post('password', TRUE));
        $row = $this->finance_model->getOne($data);
        if(!$row) {
            show400('手机号或者交易密码错误');
        }
        $res = $this->finance_model->del($data['id']);
        if ($res)//用户名密码错误
        {
            show200('解绑成功');
        }else{
            show400('解绑失败');
        }
    }
}
/* End of file Login.php */